package com.itheima.tliasmanager.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.tliasmanager.mapper.EmpLogMapper;
import com.itheima.tliasmanager.mapper.OperateLogMapper;
import com.itheima.tliasmanager.pojo.Dto.QueryParam;
import com.itheima.tliasmanager.pojo.Vo.PageResult;
import com.itheima.tliasmanager.pojo.domain.Clazz;
import com.itheima.tliasmanager.pojo.domain.EmpLog;
import com.itheima.tliasmanager.pojo.domain.OperateLog;
import com.itheima.tliasmanager.service.LogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
@Service
public class LogServiceImpl implements LogService {

    @Autowired
    private EmpLogMapper empLogMapper;

    @Autowired
    private OperateLogMapper operateLogMapper;

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    @Override
    public void insertLog(EmpLog empLog) {
        log.info("员工保存操作日志：参数: {}", empLog);
        empLogMapper.insert(empLog);
    }

    @Override
    public PageResult<OperateLog> page(QueryParam queryParam) {
        log.info("S ------> 分页查询日志列表，参数：{}",queryParam);
        PageHelper.startPage(queryParam.getPage(),queryParam.getPageSize());
        Page<OperateLog> page = (Page<OperateLog>)operateLogMapper.queryPageList(queryParam);

        PageResult<OperateLog> pageResult = new PageResult<>(page.getTotal(), page.getResult());
        log.info("分页查询结果：{}",pageResult);


        return pageResult;
    }
}
